package com.jy.adscm.operation.cg.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.cg.bean.CgBom;
import com.jy.adscm.operation.cg.bean.JqPlan;
import com.jy.adscm.operation.cg.bean.QueryCondition;
import com.jy.adscm.operation.cg.bean.QueryJqPlan;
import com.jy.adscm.operation.cg.service.CgBomService;
import com.jy.adscm.operation.cg.service.JqPlanService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-07-26
 */
@RestController
@RequestMapping("adscm/operation/cg/jqPlan")
public class JqPlanController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JqPlanService jqPlanService;
    @RequestMapping("selectJqPlan")
    public SimpleCoreResponse selectJqPlan(@RequestBody QueryJqPlan  queryJqPlan , HttpServletRequest request) throws AdscmSystemException {
        Page<JqPlan> page =new Page<>(queryJqPlan.getCurrentPage(),queryJqPlan.getPageSize());
        page= jqPlanService.selectJqPlan(page,queryJqPlan);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("insert")
    public SimpleCoreResponse insertJqPlan(@RequestBody QueryCondition queryCondition , HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
       boolean  result=  jqPlanService.insertJqPlanByPlan(queryCondition,token);
        return  new SimpleCoreResponse("200","查询成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update( @RequestBody JqPlan jqPlan, HttpServletRequest request) throws AdscmSystemException {
        boolean c = jqPlanService.updateById(jqPlan);
        return  new SimpleCoreResponse("200","查询成功",c);
    }
    @RequestMapping("approve/{id}")
    public SimpleCoreResponse approve(@PathVariable Integer id, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean result=  jqPlanService.approve(id,token);
        return  new SimpleCoreResponse("200","查询成功",result);
    }
    @RequestMapping("approves")
    public SimpleCoreResponse approves(@RequestBody List<Integer> ids, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean result=  jqPlanService.approves(ids,token);
        return  new SimpleCoreResponse("200","查询成功",result);
    }


}

